package com.xsq.testnetty;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.xsq.netty.NettyConfig;
import com.xsq.netty.NettyHelper;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        NettyConfig config = new NettyConfig.Builder()
                .setOpenLog(false)//是否打印日志
                .setHost("192.168.1.103")//连接服务器的ip地址
                .setPort(8080)//连接服务器的端口号
                .setHeartbeatInterval(45 * 1000) //心跳间隔
                .setServicePackageName(getPackageName())//netty服务的包名
                .setIsService(true)//是否服务端 用于多个应用共用一个netty服务场景
                .setIsAutoConnect(true)//是否自动连接，与setIsService方法配合使用
                .build();
        //初始化netty
        NettyHelper.init(getApplicationContext(), config);

    }
}